package model;

import java.util.Random;

import model.thread.ThreadUtil;

import org.apache.log4j.Logger;

import business.iservices.FactoryBusinessSrv;

/**
 * Modelo para la funcionalidad de creacion de la bases
 * @author 53385255R
 *
 */
public class BaseCreationModel {

	private ThreadUtil threadUtil;
	private Logger _log;
	private DBConf _dbConf;
	private Integer modelId;
	
	public BaseCreationModel() {
		
		_log = Logger.getLogger("BaseCreationModel");
		modelId =  new Random().nextInt();
		threadUtil = new ThreadUtil(modelId);
	}
	
	
	/**
	 * Procesa la creacion de la base de datos BASe.
	 */
	public void createSqliteBase() {

		if ((_dbConf != null) && (_dbConf.getMaescorpPath() != null) && (_dbConf.getSqlitePath() != null)) {
			threadUtil.executeWithThread(threadUtil.METHOD_MAESCORP_PARSER, null);
			threadUtil.executeWithThread(threadUtil.METHOD_CLOSE,null);
		}

		
	}


	public void set_dbConf(DBConf _dbConf) {
		this._dbConf = _dbConf;
		
		if ((_dbConf != null) && (_dbConf.getSqlitePath() != null))
			FactoryBusinessSrv.getInstance().getDataBasesService(modelId).setSQLite(_dbConf.getSqlitePath());
		if ((_dbConf != null) && (_dbConf.getSqlNewCorpsPath() != null))
			FactoryBusinessSrv.getInstance().getDataBasesService(modelId).setNewCorps(_dbConf.getSqlNewCorpsPath());
		if ((_dbConf != null) && (_dbConf.getMaesorgPath() != null))
			FactoryBusinessSrv.getInstance().getDataBasesService(modelId).setMaesorg(_dbConf.getMaesorgPath());
		if ((_dbConf != null) && (_dbConf.getMaescorpPath() != null))
			FactoryBusinessSrv.getInstance().getDataBasesService(modelId).setMaescorp(_dbConf.getMaescorpPath());
			
	}


	public DBConf get_dbConf() {
		return _dbConf;
	}


	
}
